package cate.game.role.bag.favorability;

import cp.solution.pattern.ICopiable;
import cp.solution.util.collection.MapKit;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import lombok.ToString;

import java.util.HashMap;
import java.util.Map;

@NoteClass("好感度属性数据")
@ToString
public class FavorabilityAttr implements ICopiable<FavorabilityAttr> {
    @NoteField("属性tid")
    public int attrId;

    @NoteField("<道具tid, 次数>")
    public Map<Integer, Integer> times;

    @NoteField("增加的值")
    public double value;

    public FavorabilityAttr(){

    }

    public FavorabilityAttr(int attrId) {
        this.attrId = attrId;
        this.times = new HashMap<>();
    }

    public void initialize(){
        if (times == null) {
            times = new HashMap<>();
        }
    }

    public void addValue(int tid, int times, double value) {
        this.times.put(tid, this.times.getOrDefault(tid, 0) + times);
        this.value += value;
    }

    @Override
    public FavorabilityAttr copy() {
        FavorabilityAttr cp = new FavorabilityAttr();
        cp.attrId = attrId;
        cp.times = MapKit.clone(times);
        cp.value = value;
        return cp;
    }

    public void reset() {
        this.value = 0;
        this.times.clear();
    }
}
